SHARED Statement ---------------------------------------------------------------------------- Action Gives a SUB or FUNCTION procedure access to variables declared at the module level without passing them as parameters. Syntax SHARED variable( ) AS type , variable( ) AS type... Remarks The argument variable is the module-level variable the procedure will use. It is either an array name followed by ( ), or a variable name. The AS type clause can be used to indicate the variable's type, which can be INTEGER, LONG, SINGLE, DOUBLE, STRING, fixed-length string ( STRING * length), CURRENCY, or a user-defined type. By using either the SHARED statement in a SUB or FUNCTION procedure, or the SHARED attribute with COMMON or DIM in the module-level code, you can use variables in a procedure without passing them as parameters. The SHARED attribute used with COMMON or DIM shares variables among all procedures in a module, while the SHARED statement shares variables between a single procedure and the module-level code. Note The SHARED statement shares variables only within a single compiled module. It does not share variables with programs in the Quick library or with procedures compiled separately and linked to the program. The SHARED statement shares variables only between the module-level code and a SUB or FUNCTION procedure in the same module. The SHARED statement can appear only in a SUB or FUNCTION procedure. For more information, see Chapter 2, "SUB and FUNCTION Procedures" in the Programmer's Guide. See Also COMMON, DIM, SUB Example The following example calls a SUB procedure named Convert that converts the input decimal number to its string representation in the given new base. The string N$ is shared by the procedure and the main program. DEFINT A-Z DO INPUT "Decimal number (input number <= 0 to quit). ",Decimal IF Decimal <= 0 THEN EXIT DO INPUT "New base. ",Newbase N$ = "" PRINT Decimal "base 10 equals "; DO WHILE Decimal > 0 CALL Convert (Decimal,Newbase) Decimal = Decimal\Newbase LOOP PRINT N$ " base" Newbase PRINT LOOP SUB Convert (D,Nb) STATIC SHARED N$ ' Take the remainder to find the value of the current ' digit. R = D MOD Nb ' If the digit is less than ten, return a digit (0-9). ' Otherwise, return a letter (A-Z). IF R < 10 THEN Digit$ = CHR$(R+48) ELSE Digit$ = CHR$(R+55) N$ = RIGHT$(Digit$,1) + N$ END SUB